package cn.yunyichina.provider.iface.entity.common;

import java.io.Serializable;

/**
 * 云医通络标准接口响应报文封装
 *
 * @author zhangkw
 * @date 2016-07-28
 */
public class Response implements Serializable {

    public static final String SUCCESS_CODE = "0";

    public static final String SUCCESS_MESSAGE = "success";

    public static final String FAILURE_CODE = "-1";

    public static final String FAILURE_MESSAGE = "failure";

    private String resultCode;

    private String resultMessage;

    private String result;
    
    public Response() {
        super();
        this.resultCode = SUCCESS_CODE;
        this.resultMessage = SUCCESS_MESSAGE;
    }

    public Response(String resultCode, String resultMessage) {
        super();
        this.resultCode = resultCode;
        this.resultMessage = resultMessage;
    }

    public Response(String resultCode, String resultMessage, String result) {
        super();
        this.resultCode = resultCode;
        this.resultMessage = resultMessage;
        this.result = result;
    }

    public static Response success() {
        return new Response(SUCCESS_CODE, SUCCESS_MESSAGE);
    }

    public static Response success(String data) {
        return new Response(SUCCESS_CODE, SUCCESS_MESSAGE, data);
    }

    public static Response failure() {
        return new Response(FAILURE_CODE, FAILURE_MESSAGE);
    }

    public static Response failure(String data) {
        return new Response(FAILURE_CODE, FAILURE_MESSAGE, data);
    }

    public static Response failure(String code, String message) {
        return new Response(code, message);
    }

    public void setResultCodeAndMessage(String resultCode, String resultMessage) {
        this.resultCode = resultCode;
        this.resultMessage = resultMessage;
    }

    public void setResultCodeAndMessageAndResult(String resultCode, String resultMessage, String result) {
        this.resultCode = resultCode;
        this.resultMessage = resultMessage;
        this.result = result;
    }

    public Response buildResult(String result) {
        this.result = result;
        return this;
    }

    public Response buildResultCodeAndMessage(String resultCode, String resultMessage) {
        this.resultCode = resultCode;
        this.resultMessage = resultMessage;
        return this;
    }

    public Response buildResultCodeAndMessageAndResult(String resultCode, String resultMessage, String result) {
        this.resultCode = resultCode;
        this.resultMessage = resultMessage;
        this.result = result;
        return this;
    }

    public String getResultCode() {
        return resultCode;
    }

    public String getResultMessage() {
        return resultMessage;
    }

    public String getResult() {
        return result;
    }

    public void setResult(String result) {
        this.result = result;
    }

    public boolean isSuccess() {
        return "0".equals(resultCode);
    }

}
